<!DOCTYPE html>
<html lang="en">
<head>
    <title>公司进个人管理层</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=4a6c1b54">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <script src="https://file.ggxqce.com/web/vue.min.js"></script>
    <style>
        .reginTd {
            max-width: 105px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            position: relative;
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .row {
            margin-right: -15px;
            margin-left: 0px;
        }

        .col-lg-6, .col-xs-6, .col-md-6 {
            padding-left: 0;
        }
    </style>
</head>
<body>
<section class="content" id="app">
    <div class="div-td-content-more"><i></i></div>
    <div class="nav-tabs-custom oaReportNav" v-cloak>
        <!-- Tabs within a box -->
        <ul class="nav nav-tabs pull-right" style="margin-bottom: 10px;">
            <li :class="isActive(today)?'active':''"
                @click="refreshData('bigVisitCustomer','get_bigVisitDepart',today)"><a href="#sales-chart"
                                                                                       data-toggle="tab">今日</a></li>
            <li :class="isActive(yesterday)?'active':''"
                @click="refreshData('bigVisitCustomer','get_bigVisitDepart',yesterday)"><a href="#sales-chart"
                                                                                           data-toggle="tab">昨日</a></li>
            <li :class="isActive(thisWeek)?'active':''"
                @click="refreshData('bigVisitCustomer','get_bigVisitDepart',thisWeek)"><a href="#sales-chart"
                                                                                          data-toggle="tab">本周</a></li>
            <li :class="isActive(thisMonth)?'active':''"
                @click="refreshData('bigVisitCustomer','get_bigVisitDepart',thisMonth)"><a href="#sales-chart"
                                                                                           data-toggle="tab">本月</a></li>
            <li :class="isActive(item.time)?'active':''" v-for="(item,i) in tab"
                @click="refreshData('bigVisitCustomer','get_bigVisitDepart',item.time)"><a href="#sales-chart"
                                                                                           data-toggle="tab">{{i==0?"上月":item.str}}</a>
            </li>
        </ul>
    </div>
    <div class="div-td-content-more"><i></i></div>
    <div style="padding: 0 10px;background: #fff;display: flex;justify-content: space-between;"
         id="bigVisitDepart">
        <div style="width: 49%;" class="mScrollBox">
            <table class="table table-bordered text-center table-width">
                <thead>
                <tr style="height:35px;">
                    <th align="center" style="width:40px">序号</th>
                    <th style="width:72px">面访排名</th>
                    <th style="width:50px">完成</th>
                    <th style="width:60px">完成率</th>
                    <th style="width:80px">大客户经理</th>
                    <th style="width:80px">大客户总监</th>
                    <th v-if="bigVisitCustomer.time.length!=10" style="width:50px">出勤</br>天数</th>
                    <th v-if="bigVisitCustomer.time.length!=10" style="width:50px">日均</br>完成</th>
                    <th>大区</th>
                </tr>
                </thead>
                <tbody v-cloak>
                <tr v-for="(item,i) in bigVisitCustomer.faceList">
                    <td>{{i+1}}</td>
                    <td>{{item.rownum}}</td>
                    <template v-if="isGo(item)">
                        <td style="color:#169BD5;cursor: pointer" @click="openInterview(item,'1')"
                            v-if="item.complete!='-'">{{item.complete}}
                        </td>
                        <td v-else>{{item.complete}}</td>
                    </template>
                    <template v-else>
                        <td>{{item.complete}}</td>
                    </template>
                    <td v-if="item.completionRate!=''&&item.completionRate!='-'">{{item.completionRate}}%</td>
                    <td v-else-if="item.completionRate=='-'">{{item.completionRate}}</td>
                    <td v-else>-</td>

                    <td v-if="isGo(item)" class="openUserBox" :attrid="item.userId"
                        @click="lookPersonnelDepartList(item)">
                        <span v-if="item.managerName">{{item.managerName}}</span>
                        <span v-else style="color: #CCCCCC;">空缺</span>
                    </td>
                    <td v-else>
                        <span v-if="item.managerName">{{item.managerName}}</span>
                        <span v-else style="color: #CCCCCC;">空缺</span>
                    </td>
                    <td><span v-if="item.bigManagerName">{{item.bigManagerName}}</span>
                        <span v-else style="color: #CCCCCC;">空缺</span>
                    </td>
                    <td v-if="bigVisitCustomer.time.length!=10">{{item.signManagerNum}}</td>
                    <td v-if="bigVisitCustomer.time.length!=10">{{item.averageComplete}}</td>
                    <td>{{item.departName}}</td>
                </tr>
                <tr>
                    <td colspan="2">合计</td>
                    <td>{{allDate[1].allComplete}}</td>
                    <td>-</td>
                    <td>-</td>
                    <td>-</td>
                    <td v-if="bigVisitCustomer.time.length!=10">{{allDate[1].signManagerNum}}</td>
                    <td v-if="bigVisitCustomer.time.length!=10">-</td>
                    <td>-</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div style="width: 49%;float:right;" class="mScrollBox">
            <table class="table table-bordered text-center table-width">
                <thead>
                <tr style="height:35px;">
                    <th align="center" style="width:40px">序号</th>
                    <th style="width:72px">电访排名</th>
                    <th style="width:50px">完成</th>
                    <th style="width:60px">完成率</th>
                    <th style="width:80px">大客户经理</th>
                    <th style="width:80px">大客户总监</th>
                    <th v-if="bigVisitCustomer.time.length!=10" style="width:50px">出勤</br>天数</th>
                    <th v-if="bigVisitCustomer.time.length!=10" style="width:50px">日均</br>完成</th>
                    <th>大区</th>
                </tr>
                </thead>
                <tbody v-cloak>
                <tr v-for="(item,i) in bigVisitCustomer.telList">
                    <td>{{i+1}}</td>
                    <td>{{item.rownum}}</td>
                    <template v-if="isGo(item)">
                        <td style="color:#169BD5;cursor: pointer" @click="openInterview(item,'1')"
                            v-if="item.complete!='-'">{{item.complete}}
                        </td>
                        <td v-else>{{item.complete}}</td>
                    </template>
                    <template v-else>
                        <td>{{item.complete}}</td>
                    </template>
                    <td v-if="item.completionRate!=''&&item.completionRate!='-'">{{item.completionRate}}%</td>
                    <td v-else-if="item.completionRate=='-'">{{item.completionRate}}</td>
                    <td v-else>-</td>

                    <td v-if="isGo(item)" class="openUserBox" :attrid="item.userId"
                        @click="lookPersonnelDepartList(item)">
                        <span v-if="item.managerName">{{item.managerName}}</span>
                        <span v-else style="color: #CCCCCC;">空缺</span>
                    </td>
                    <td v-else>
                        <span v-if="item.managerName">{{item.managerName}}</span>
                        <span v-else style="color: #CCCCCC;">空缺</span>
                    </td>
                    <td><span v-if="item.bigManagerName">{{item.bigManagerName}}</span>
                        <span v-else style="color: #CCCCCC;">空缺</span>
                    </td>
                    <td v-if="bigVisitCustomer.time.length!=10">{{item.signManagerNum}}</td>
                    <td v-if="bigVisitCustomer.time.length!=10">{{item.averageComplete}}</td>
                    <td>{{item.departName}}</td>
                </tr>
                <tr>
                    <td colspan="2">合计</td>
                    <td>{{allDate[0].allComplete}}</td>
                    <td>-</td>
                    <td>-</td>
                    <td>-</td>
                    <td v-if="bigVisitCustomer.time.length!=10">{{allDate[0].signManagerNum}}</td>
                    <td v-if="bigVisitCustomer.time.length!=10">-</td>
                    <td>-</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>

    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=602456c3"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=6348cbbc"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/highcharts/highcharts.js"></script>
<script type="text/javascript">
    $(function () {
        $("body").on("click", ".reginTd", function (e) {
            var text = $(this).text();
            if (text != "") {
                text = "<i></i>" + text;
                $(".div-td-content-more").html(text).css({
                    "width": $(this).outerWidth() + "px",
                    "left": $(this).offset().left,
                    "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                }).show();
                e.stopPropagation();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });

</script>
<script type="text/javascript">
    console.log(urlConfig);
    var app = new Vue({
        el: '#app',
        data: {
            currentUser: getCurrentUser(),
            companyId: $.wyui.page.urlParams.companyId,
            months: [],
            dateTime: $.wyui.page.urlParams.dateTime,
            yesterday: new Date(new Date() - 24 * 60 * 60 * 1000).Format("yyyy-MM-dd"),
            today: new Date().Format("yyyy-MM-dd"),
            thisMonth: new Date().Format("yyyy-MM"),
            thisWeek: new Date().Format("yyyy-MM-dd") + "-w",
            hour: new Date().getHours(),
            tab: [],
            reginIds: [],
            bigVisitCustomer: {
                time: $.wyui.page.urlParams.dateTime,
                faceList: [],
                telList: [],
            },
            allDate: [{"allComplete": "", "completionRate": ""}, {"allComplete": "", "completionRate": ""}],
        },
        methods: {
            //tab中点击日期刷新对应数据
            refreshData: function (dataType, fun, time) {
                var that = this;
                that[dataType].time = time;
                that[fun]();
            },
            //获取tab
            getTab: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");

                for (var i = 0; i < 5; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.tab.push(that.insert_flg(dateTime, "-", "4"))
                }
                console.log(that.tab)
            },
            isActive: function (item) {
                var that = this;
                if (that.bigVisitCustomer.time == item) {
                    return true;
                }
            },
            getLastEndMonth: function (beginYearMonth) {
                var strYear = parseInt(beginYearMonth.substr(0, 4), 10);
                var strMonth = parseInt(beginYearMonth.substr(4, 6), 10);
                if (strMonth - 1 == 0) {
                    strYear -= 1;
                    strMonth = 12;
                } else {
                    strMonth -= 1;
                }
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var monthstr = strYear + "" + strMonth;
                return monthstr;
            },
            //格式化日期
            insert_flg: function (str, flg, sn, type) {
                var newstr = "";
                for (var i = 0; i < str.length; i += sn) {
                    var tmp = str.substring(i, i + sn);
                    newstr += tmp + flg;
                }
                newstr = newstr.substr(0, newstr.length - 1);
                var st1 = newstr.substr(2, 2);
                var st2 = newstr.substr(5, 2);
                var newstr3 = st2 + "/" + st1;
                var obj = {str: newstr, time: newstr};
                return obj;
            },
            isHasRightOp: function (regionId) {
//                console.log($.inArray(regionId, this.reginIds) > -1)
                return $.inArray(regionId, this.reginIds) > -1;
            },
            isGo: function (item) {
                var that = this;
                if (that.isHasRightOp(item.regionId)) {
                    return true
                } else {
                    return false
                }
            },
            getCount: function (arr, key) {
                var number = 0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number += (arr[i][key] && arr[i][key] != '-' ? arr[i][key] : 0)

                }
                return number;
            },
            lookPersonnelDepartList: function (item) {
                top.addTabs({
                    id: "look" + item.id,
                    title: item.managerName + "详情",
                    close: true,
                    url: '/personnel/entry.html?id=' + item.userId + '&pageType=look'
                });
            },
            getAll: function (arr, type) {
                console.log(this.regionInfo)
                if (type == "0") {
                    this.allDate[0].target = this.getCount(arr, "target");
                    this.allDate[0].allComplete = this.getCount(arr, "complete");
                    this.allDate[0].signManagerNum = this.getCount(arr, "signManagerNum");
                   /* if (this.allDate[0].signManagerNum == 0) {
                        this.allDate[0].averageComplete = "0.00";
                    } else {
                        this.allDate[0].averageComplete = (this.allDate[0].allComplete / this.allDate[0].signManagerNum).toFixed(2);
                    }*/
                    if (this.allDate[0].target == 0) {
                        this.allDate[0].completionRate = "0.00%";
                    } else {
                        this.allDate[0].completionRate = (this.allDate[0].allComplete / this.allDate[0].target * 100).toFixed(2) + "%";
                    }
                } else {
                    this.allDate[1].target = this.getCount(arr, "target");
                    this.allDate[1].allComplete = this.getCount(arr, "complete");
                    this.allDate[1].signManagerNum = this.getCount(arr, "signManagerNum");
                    /*if (this.allDate[1].signManagerNum == 0) {
                        this.allDate[1].averageComplete = "0.00";
                    } else {
                        this.allDate[1].averageComplete = (this.allDate[1].allComplete / this.allDate[1].signManagerNum).toFixed(2);
                    }*/
                    if (this.allDate[1].target == 0) {
                        this.allDate[1].completionRate = "0.00%";
                    } else {
                        this.allDate[1].completionRate = (this.allDate[1].allComplete / this.allDate[1].target * 100).toFixed(2) + "%";
                    }
                }
            },
            getRegionByUserId: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.report.bigVisitCustomer.getRegionByUserId, {userId: getCurrentUser().id}, function (ids) {
                    for (var i = 0; i < ids.length; i++) {
                        that.reginIds.push(ids[i].regionId);
                    }
//                    console.log(that.reginIds)
                }, true);
            },
            //获取拜访报表-区域经理
            get_bigVisitDepart: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.report.bigVisitCustomer.getAllManagerByCompanyId, {
                    "companyId": that.companyId,
                    "dateTime": that.bigVisitCustomer.time,
                    "type": "1"
                }, function (data) {
                    var data = trimRN2(data);
                    that.bigVisitCustomer.faceList = data;
                    that.getAll(that.bigVisitCustomer.faceList, "1");
                }, false, "#bigVisitRegion");
                $.wyui.postMethod(urlConfig.report.bigVisitCustomer.getAllManagerByCompanyId, {
                    "companyId": that.companyId,
                    "dateTime": that.bigVisitCustomer.time,
                    "type": "0"
                }, function (data) {
                    var data = trimRN2(data);
                    that.bigVisitCustomer.telList = data;
                    that.getAll(that.bigVisitCustomer.telList, "0");
                }, false, "#bigVisitRegion");
            },
//            //查拜访个人下级页面
//            lookInterviewCustomerList:function(item,type){
//                var that=this;
//                url = "reportForm/interview/interviewCustomerList.html";
//                top.closeTabByPageId("lookInterviewCustomerList");
//                top.addTabs({id:"lookInterviewCustomerList",title:item.managerName,close: true,url:url+ '?userId=' +item.userId+"&dateTime="+that.bigVisitCustomer.time});
//            },
            openInterview: function (item, type) {
                var that = this;
                top.closeTabByPageId("khList2");
                top.addTabs({
                    id: 'khList2',
                    title: type == 1 ? item.managerName + '面访' : item.managerName + '电访',
                    close: true,
                    url: 'reportForm/interview/interviewCustomerList.html?userId=' + item.userId + "&dateTime=" + that.bigVisitCustomer.time + "&name=" + item.managerName + "&type=" + type,
                });
            },
        },
        mounted: function () {
            var that = this;
            //获取前5个月 拼接出日期筛选框
            //查看参数
            if (!that.companyId) {
                that.companyId = getCurrentUser().companyId;
            }
            if (!that.dateTime) {
                that.dateTime = new Date().Format("yyyy-MM-dd");
            }
            //获取前5个月的tab数据
            this.getTab();
            //获取数据
            //获取可查看区域权限
            that.getRegionByUserId();
            that.get_bigVisitDepart();
        }

    });
</script>
</body>
</html>